//
//  array_signature.c
//  compilation
//
//  Created by Kevin Le perf on 17/01/12.
//  Copyright (c) 2012 e2co technologie. All rights reserved.
//
#include <stdlib.h>
#include <stdio.h>
#include "array_signature.h"
/*
struct array_signature{
	size_t _stack[32]; //last argument = first in this array
	int _number; //number of []
};*/

void array_free(void * f){
	free(f);
}

struct array_signature * array_create(){
	struct array_signature * a = malloc(sizeof(*a));
	a->_number = 0;
	return a;
}
/*
 ajoute la taille de la dimension
 retourne 0 si ok
 retourne -1 si a == null 
 retourne -2 si on a depasse 32 []*/
int array_add(struct array_signature * a, int t){
	if(a != NULL){
		if(a->_number < 32){
			a->_stack[a->_number] = t;
			a->_number++;
			printf("adding %d",t);
			return 0;
		}
		return -2;
	}
	return -1;
}
/*
 retourne le nombre de dimension du tableau 0 si erreur ou non declare*/
int array_get_dim(struct array_signature * a){
	if(a != NULL && a->_number != 0){
		return a->_number;
	}
	return 0;
}
/*
 retourne la taille de la dimension i du tableau 
 -1 si erreur */
int array_get_size_dim(struct array_signature * a, int i){
	if(a != NULL){
		return a->_stack[a->_number-i-1];
	}
	return -1;
}

void array_print(struct array_signature * s){
	int i=s->_number - 1;
	for(; i >=0;i--){
		printf("[%d]", s->_stack[i]);
	}
}